package com.doudou.commons.entity;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @Author: 傻男人
 * @Date: 2020/6/4 11:29
 * @Version: 1.0
 * @Description:
 */
@Data
@ApiModel("分页模型")
public class PaginationSupport<T> implements Serializable {

    @ApiModelProperty("数据")
    private List<T> records;

    @ApiModelProperty("总数")
    private long total;

    @ApiModelProperty("每页查询数量")
    private long size;

    @ApiModelProperty("当前页码")
    private long current;

    @ApiModelProperty("总页码数")
    private long pages;

    public PaginationSupport(){}

    private PaginationSupport(IPage<T> page){
        this.records = page.getRecords();
        this.total = page.getTotal();
        this.size = page.getSize();
        this.current = page.getCurrent();
        this.pages = page.getPages();
    }

    public static <T>PaginationSupport<T> instance(IPage<T> page){
        return new PaginationSupport(page);
    }

}
